package com.franklin.java.api.psi.data.resolver;

import com.franklin.java.api.psi.data.PsiData;
import com.franklin.java.utils.PsiUtils;
import com.franklin.plugins.common.utils.DataCheckUtils;
import com.franklin.plugins.common.utils.PatternUtils;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaFile;


/**
 * @author Franklin
 * @since 2021/08/15/ 21:34
 */
public class NewObjectResolver implements PsiDataResolver {
    @Override
    public PsiData resolve(String name, String value, PsiElement dataElement) {
        //直接new 对象
        if (!value.contains("new ")){
            return null;
        }
        PsiElement psiElement = dataElement;
        String val = value;
        String type = "String";
        String typeFullName = "java.lang.String";

        String implementType = PatternUtils.findImplementType(value);
        if (DataCheckUtils.isNotEmpty(implementType)) {
            type = implementType;
        }
        typeFullName = PsiUtils.findTypeFullName((PsiJavaFile) dataElement.getContainingFile(), type);
        type = PsiUtils.getSimpleClassName(type);
        return new PsiData(type,val,psiElement,typeFullName, dataElement);
    }
}
